# Maintainer: justforlxz <justforlxz@gmail.com>
pkgname=deepin-daemon-git
pkgver=6.0.0.r85.gf8733f93
pkgrel=1
sourcename=dde-daemon
sourcetars=("$sourcename"_"$pkgver".tar.xz vendor.tar.gz)
sourcedir="$sourcename"
useforobs=1
pkgdesc='Daemon handling the DDE session settings'
arch=('x86_64' 'aarch64')
url="https://github.com/linuxdeepin/dde-daemon"
license=('GPL3')
depends=('deepin-desktop-schemas-git' 'ddcutil' 'deepin-api-git' 'gvfs' 'iso-codes' 'lsb-release'
         'mobile-broadband-provider-info' 'deepin-polkit-agent-git'
         'deepin-polkit-agent-ext-gnomekeyring-git' 'udisks2' 'upower'
         'libxkbfile' 'accountsservice' 'deepin-desktop-base-git' 'bamf' 'pulseaudio'
         'org.freedesktop.secrets' 'noto-fonts' 'imwheel' 'ddcutil')
makedepends=('deepin-api-git' 'sqlite' 'deepin-gettext-tools-git'
             'git' 'mercurial' 'python-gobject' 'networkmanager' 'bluez' 'go' 'ddcutil')
optdepends=('networkmanager: for network management support'
            'bluez: for bluetooth support'
            'iw: for miracast module'
            'proxychains-ng: for proxy configuration module')
conflicts=('deepin-daemon')
provides=('deepin-daemon')
groups=('deepin-git')
install="$pkgname.install"
source=("${sourcetars[@]}"
        dde-daemon.patch
        'deepin-daemon.sysusers')
sha512sums=('SKIP' 'SKIP'
            'SKIP'
            '808c02d4fec4cbbb01119bbb10499090199e738b7dd72c28a57dde098eef6132723f3434c151f79e21d9f788c7f7bae8046573ac93ba917afe0e803fbffa6d5a')

prepare() {
  cd $sourcedir
  patch -p1 -i ../dde-daemon.patch
  rm -rf system/uadp
  rm -rf session/uadpagent
  export GOPATH="$srcdir/build:/usr/share/gocode"
  sed -i 's#/usr/share/backgrounds/default_background.jpg#/usr/share/backgrounds/deepin/desktop.jpg#' accounts1/user.go
}

build() {
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  cd $sourcedir
  if [[ ! -n "$useforobs" ]];then
    export GOFLAGS="-buildmode=pie -trimpath -modcacherw -mod=readonly"
    go mod tidy
  else
    export GOFLAGS="-buildmode=pie -trimpath -modcacherw -mod=vendor"
    mv "$srcdir"/vendor "$srcdir"/"$sourcedir"/vendor
  fi
  make
}

package() {
  cd $sourcedir
  make DESTDIR="$pkgdir" PAM_MODULE_DIR=usr/lib/security install

  mv "$pkgdir"{,/usr}/lib/systemd
  mv "$pkgdir"{,/usr}/lib/udev
  rmdir "$pkgdir"/lib

  install -Dm644 ../deepin-daemon.sysusers "$pkgdir/usr/lib/sysusers.d/deepin-daemon.conf"
}
